<%@page import="java.util.ArrayList"%>
<%@page import="com.shsh.safemanage.dao.AccidentDao"%>
<%@page import="com.shsh.safemanage.model.ProblemTransfer"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.ProblemDao"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%@page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.model.Role"%>
<%@page import="com.shsh.safemanage.model.AccidentFacade"%>
<%@page import="com.shsh.safemanage.model.AbstractAccident"%>
<%@page import="com.shsh.safemanage.action.UserAction"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="java.util.List"%>
<%
{
UserAction innerUserAction = ActionCreator.createUserAction();
Role innerRole = innerUserAction.getUserRole(request);
ProblemDao innerProblemDao = DaoCreator.createProblemDao();
AccidentDao innerAccidentDao = DaoCreator.createAccidentDao();
User innerUser = (User)session.getAttribute(Constants.SESSION_USER);
List<ProblemTransfer> innerTransferList = null;
AccidentFacade facade = (AccidentFacade)request.getAttribute(Constants.REQUEST_ATTRIBUTE_ACCIDENT_FACADE);

boolean roleCanWrite = innerRole.getRoleLevel() >= Constants.ROLE_LEVEL_KEJI;
%>
	<tr>
		<td><%=facade.getDepartment1Name()==null?"&nbsp;":facade.getDepartment1Name()%></td>
		<td><%=facade.getEquipmentName()==null?"&nbsp;":facade.getEquipmentName()%></td>
		<td><%=facade.getAccidentType()==null?"&nbsp;":facade.getAccidentType()%></td>
		<td align="center"><%=facade.getAccidentName()==null?"&nbsp;":facade.getAccidentName()%></td>
		<td align="center"><%=Util.formatDateTime(facade.getAccidentTime())%></td>
		<td align="center">
			<%
			AbstractAccident accident = facade.getRegisterForm();
			if(accident.getAccidentWriteUserID() != null) {
				innerTransferList = innerProblemDao.getProblemTransfer(accident.getId(), innerUser.getId());
			} else {
				innerTransferList = new ArrayList<ProblemTransfer>();
			}
			if(innerTransferList.size()>0) {
			%>
			<a href="#" onclick="javascirpt:feedbackRegisterform(<%=accident.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
			<% 
			} else {
			%>
			<font style="color:gray;"><%=accident.getAccidentStatusLabel()%></font>
			<%
			}
			%>
		</td>
		<td align="center">
			<%
			accident = facade.getInfoSheet();
			if(accident.getAccidentWriteUserID() != null) {
				innerTransferList = innerProblemDao.getProblemTransfer(accident.getId(), innerUser.getId());
			} else {
				innerTransferList = new ArrayList<ProblemTransfer>();
			}
			
			if(innerTransferList.size() > 0) {
				//已流转到，只可能为“修改”与"完成"状态，直接显示。
				%>
				<a href="#" onclick="javascirpt:feedbackInfosheet(<%=accident.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
				<% 
			} else if (roleCanWrite 
					&& accident.statusMatches(Constants.ACCIDENT_STATUS_APPLICATION) 
					&& facade.getRegisterForm().statusMatches(Constants.ACCIDENT_STATUS_COMPLETE)){
				//未流转到。只允许科级及以上人员申报,并且上一份报告已“完成”
				%>
				<a href="#" onclick="javascirpt:writeInfosheet(<%=facade.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
				<% 				
			} else {
				%>
				<font style="color:gray;"><%=accident.getAccidentStatusLabel()%></font>
				<%
			}
			%>
		</td>
		<td align="center">
			<%
			accident = facade.getQuickReport();
			if(accident.getAccidentWriteUserID() != null) {
				innerTransferList = innerProblemDao.getProblemTransfer(accident.getId(), innerUser.getId());
			} else {
				innerTransferList = new ArrayList<ProblemTransfer>();
			}
			
			if(innerTransferList.size() > 0) {
				//已流转到，只可能为“修改”与"完成"状态，直接显示。
				%>
				<a href="#" onclick="javascirpt:feedbackQuickreport(<%=accident.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
				<% 
			} else if (roleCanWrite 
					&& accident.statusMatches(Constants.ACCIDENT_STATUS_APPLICATION) 
					&& facade.getRegisterForm().statusMatches(Constants.ACCIDENT_STATUS_COMPLETE)){
				//未流转到。只允许科级及以上人员申报,并且上一份报告已“完成”
				%>
				<a href="#" onclick="javascirpt:writeQuickreport(<%=facade.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
				<% 				
			} else {
				%>
				<font style="color:gray;"><%=accident.getAccidentStatusLabel()%></font>
				<%
			}
			%>
		</td>
		<td align="center">
			<%
			accident = facade.getReport();
			if(accident.getAccidentWriteUserID() != null) {
				innerTransferList = innerProblemDao.getProblemTransfer(accident.getId(), innerUser.getId());
			} else {
				innerTransferList = new ArrayList<ProblemTransfer>();
			}
			
			if(innerTransferList.size() > 0) {
				//已流转到，只可能为“修改”与"完成"状态，直接显示。
				%>
				<a href="#" onclick="javascirpt:feedbackReport(<%=accident.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
				<% 
			} else if (roleCanWrite 
					&& accident.statusMatches(Constants.ACCIDENT_STATUS_APPLICATION) 
					&& facade.getQuickReport().statusMatches(Constants.ACCIDENT_STATUS_COMPLETE)){
				//未流转到。只允许科级及以上人员申报,并且上一份报告已“完成”
				%>
				<a href="#" onclick="javascirpt:writeReport(<%=facade.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
				<% 				
			} else {
				%>
				<font style="color:gray;"><%=accident.getAccidentStatusLabel()%></font>
				<%
			}
			%>
		</td>
		<td align="center">
			<%
			accident = facade.getCheckForm1();
			if(accident.getAccidentWriteUserID() != null) {
				innerTransferList = innerProblemDao.getProblemTransfer(accident.getId(), innerUser.getId());
			} else {
				innerTransferList = new ArrayList<ProblemTransfer>();
			}

			if(innerTransferList.size() > 0) {
				//已流转到，只可能为“修改”与"完成"状态，直接显示。
				%>
				<a href="#" onclick="javascirpt:feedbackCheckform1(<%=accident.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
				<% 
			} else if (roleCanWrite 
					&& accident.statusMatches(Constants.ACCIDENT_STATUS_APPLICATION) 
					&& facade.getQuickReport().statusMatches(Constants.ACCIDENT_STATUS_COMPLETE)){
				//未流转到。只允许科级及以上人员申报,并且上一份报告已“完成”
				%>
				<a href="#" onclick="javascirpt:writeCheckform1(<%=facade.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
				<% 				
			} else {
				%>
				<font style="color:gray;"><%=accident.getAccidentStatusLabel()%></font>
				<%
			}
			%>
		</td>
		<td align="center">
			<%
			accident = facade.getCheckForm2();
			if(accident.getAccidentWriteUserID() != null) {
				innerTransferList = innerProblemDao.getProblemTransfer(accident.getId(), innerUser.getId());
			} else {
				innerTransferList = new ArrayList<ProblemTransfer>();
			}

			if(innerTransferList.size() > 0) {
				//已流转到，只可能为“修改”与"完成"状态，直接显示。
				%>
				<a href="#" onclick="javascirpt:feedbackCheckform2(<%=accident.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
				<% 
			} else if (roleCanWrite 
					&& accident.statusMatches(Constants.ACCIDENT_STATUS_APPLICATION) 
					&& facade.getCheckForm1().statusMatches(Constants.ACCIDENT_STATUS_COMPLETE)){
				//未流转到。只允许科级及以上人员申报,并且上一份报告已“完成”
				%>
				<a href="#" onclick="javascirpt:writeCheckform2(<%=facade.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
				<% 				
			} else {
				%>
				<font style="color:gray;"><%=accident.getAccidentStatusLabel()%></font>
				<%
			}
			%>
		</td>
		<td align="center">
			<%
			accident = facade.getCheckForm3();
			if(accident.getAccidentWriteUserID() != null) {
				innerTransferList = innerProblemDao.getProblemTransfer(accident.getId(), innerUser.getId());
			} else {
				innerTransferList = new ArrayList<ProblemTransfer>();
			}

			if(innerTransferList.size() > 0) {
				//已流转到，只可能为“修改”与"完成"状态，直接显示。
				%>
				<a href="#" onclick="javascirpt:feedbackCheckform3(<%=accident.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
				<% 
			} else if (roleCanWrite 
					&& accident.statusMatches(Constants.ACCIDENT_STATUS_APPLICATION) 
					&& facade.getCheckForm2().statusMatches(Constants.ACCIDENT_STATUS_COMPLETE)){
				//未流转到。只允许科级及以上人员申报,并且上一份报告已“完成”
				%>
				<a href="#" onclick="javascirpt:writeCheckform3(<%=facade.getId() %>)" ><%=accident.getAccidentStatusLabel()%></a>
				<% 				
			} else {
				%>
				<font style="color:gray;"><%=accident.getAccidentStatusLabel()%></font>
				<%
			}
			%>
		</td>
	</tr>
<%
}
%>